//
//  WebViewController.m
//  SCMusic
//
//  Created by Steven on 2019/6/27.
//  Copyright © 2019 凌       陈. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()<UIWebViewDelegate>
@property(nonatomic, weak) IBOutlet UIWebView *webView;

@property(nonatomic, strong)UIView *launchView;
@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView.delegate = self;
   
    UIViewController *viewController = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil].instantiateInitialViewController;
    self.launchView = viewController.view;
    self.launchView.frame = self.view.bounds;
    
    [self.view addSubview:self.launchView];
    [self.view bringSubviewToFront:self.launchView];
    [self.webView loadRequest:[NSURLRequest requestWithURL:self.url]];
    
}
//主页
- (IBAction)homeAction:(UIBarButtonItem *)sender {
    
     [self.webView loadRequest:[NSURLRequest requestWithURL:self.url]];
}

//后退
- (IBAction)backAction:(UIBarButtonItem *)sender {
    
    [self.webView goBack];
}

//前进
- (IBAction)forwardAction:(UIBarButtonItem *)sender {
    
    [self.webView goForward];
}

//刷新
- (IBAction)reloadAction:(UIBarButtonItem *)sender {
    [self.webView reload];
}
//退出
- (IBAction)quitAction:(UIBarButtonItem *)sender {
    exit(0);
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    //判断是否是单击
    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        NSURL *url = [request URL];
        NSLog(@"%@",url);
        if([[UIApplication sharedApplication] canOpenURL:url])
        {
            [[UIApplication sharedApplication] openURL:url];
        }
        return NO;
    }
    return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self.launchView removeFromSuperview];
}
@end
